/* 
    Purpose: Using the 1950-2010 Censuses,
             this file calculates 4 demographic 
    		 shares (by decade): 
    		 (1) share black + female
    		 (2) share white + female
    		 (3) share black + male
    		 (4) share white + male

    Note: 1950-2010 Censuses are used so that shares
          can be calculated for when Jacome et al.
          survey respondents are around 40.
          (e.g., 1910 survey respondents will receive 
          1950 Census shares, 1920 survey respondents will 
          receive 1960 Census shares.)
          These shares will be merged to survey respondents 
          in 2_Clean_PooledData.do.

    Creates: Census_shares_byrace_bysex.dta
*/
clear
set more off
cd "$Mydirectory1/1_DataSources/CensusData/"


* Import raw data
use ./input/Census_1910to2010_1pct_raw.dta, clear //download from IPUMS USA

tab year

forval i=1950(10)2010 {

	if `i'==1950 local weight "[aw=slwt]"
	if `i'!=1950 local weight "[aw=perwt]"

	preserve

	* Keep relevant sample
	keep if year==`i'
	keep if age>=30 & age<=50
	keep if race<=2
	
	/* By Census decade: Get shares of each 
	   of 4 sex x race groups */
	gen white_men_census = race==1 & sex==1
	sum white_men `weight'
	replace white_men = `r(mean)'
	
	gen white_women_census = race==1 & sex==2
	sum white_women `weight'
	replace white_women = `r(mean)'
	
	gen black_men_census = race==2 & sex==1
	sum black_men `weight'
	replace black_men = `r(mean)'
	
	gen black_women_census = race==2 & sex==2
	sum black_women `weight'
	replace black_women = `r(mean)'
	
	* Save one observation per Census decade
	keep year white_men_census-black_women_census
	keep if _n==1
	
	tempfile data`i'
	save `data`i''
	
	
	restore
	
	}
	
 *Append all Census years
	use `data1950', clear
	append using `data1960'
	append using `data1970'
	append using `data1980'
	append using `data1990'
	append using `data2000'
	append using `data2010'
	
	rename year age40 
	
	compress
	save ./output/Census_shares_byrace_bysex.dta, replace

